public class Main {
    public static void main(String[] args) {
        System.out.println(new Solution().combinationSum4(new int[]{1, 2, 3}, 4));
    }
}


class Solution {
    public int combinationSum4(int[] nums, int target) {
        int[] dp = new int[1001];
        dp[0] = 1;
        for (int i = 0; i <= 1000; i++) {
            for (int num : nums) {
                if (i >= num) {
                    dp[i] += dp[i - num];
                }
            }
        }

//        for (int num : nums) {
//            for (int i = num; i <= 1000; i++) {
//                dp[i] = dp[i - num] + dp[i];
//            }
//        }
        return dp[target];
    }
}